home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / 4dos / 4utilsf.zip / DISPLAYK.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-10  |  11KB  |  346 lines

  1. UNIT DisplayKeyboardAndCursor;
  2. {$D-}
  3. (* ----------------------------------------------------------------------
  4.    Part of 4DESC - A Simple 4DOS File Description Editor
  5.  
  6.    (c) 1992 Copyright by David Frey,         & Tom Bowden
  7.                          Urdorferstrasse 30    1575 Canberra Drive
  8.                          8952 Schlieren ZH     Stone Mountain, GA 30088-3629
  9.                          Switzerland           USA
  10.  
  11.        Code created using Turbo Pascal 6.0 (c) Borland International 1990
  12.  
  13.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  14.                and change it free of charge, but you may not sell or hire
  15.                this part of 4DESC. The copyright remains in our hands.
  16.  
  17.                If you make any (considerable) changes to the source code,
  18.                please let us know. (send a copy or a listing).
  19.                We would like to see what you have done.
  20.  
  21.                We, David Frey and Tom Bowden, the authors, provide absolutely
  22.                no warranty of any kind. The user of this software takes the
  23.                entire risk of damages, failures, data losses or other
  24.                incidents.
  25.  
  26.    This unit manages displaying messages, switching cursor modes etc.
  27.  
  28.    ----------------------------------------------------------------------- *)
  29.  
  30. INTERFACE USES Crt;
  31.  
  32. CONST ver = '1.32';
  33.  
  34. (* Cursor *)
  35.  
  36. VAR OrigCursor : WORD;
  37.  
  38. (* Color constants for color screens: *)
  39.  
  40. CONST co_StatusFg = Blue;
  41.       co_StatusBg = Cyan;
  42.       co_DirFg    = LightCyan;
  43.       co_SelectFg = Blue;
  44.       co_SelectBg = Cyan;
  45.       co_HighFg   = LightRed;
  46.       co_NormFg   = LightGray;
  47.       co_NormBg   = Blue;
  48.       co_WarnFg   = Yellow;
  49.       co_WarnBg   = Cyan;
  50.  
  51.       (* ..and for monochrome displays: *)
  52.  
  53.       mo_StatusFg = Black;
  54.       mo_StatusBg = LightGray;
  55.       mo_DirFg    = White;
  56.       mo_SelectFg = Black;
  57.       mo_SelectBg = LightGray;
  58.       mo_HighFg   = LightGray;
  59.       mo_NormFg   = LightGray;
  60.       mo_NormBg   = Black;
  61.       mo_WarnFg   = Black;
  62.       mo_WarnBg   = White;
  63.  
  64. VAR   ScreenSize : BYTE;
  65.       MaxLines   : BYTE;
  66.       monochrome : BOOLEAN;
  67.  
  68. VAR   StatusFg   : BYTE;
  69.       StatusBg   : BYTE;
  70.       DirFg      : BYTE;
  71.       SelectFg   : BYTE;
  72.       SelectBg   : BYTE;
  73.       HighFg     : BYTE;
  74.       NormFg     : BYTE;
  75.       NormBg     : BYTE;
  76.       WarnFg     : BYTE;
  77.       WarnBg     : BYTE;
  78.       _4DOSVer   : STRING[11];
  79.       NoJust     : BOOLEAN;
  80.       FullSize   : BOOLEAN;
  81.  
  82. (* Min/Max *)
  83. FUNCTION Min(a,b : INTEGER): INTEGER;
  84. FUNCTION Max(a,b : INTEGER): INTEGER;
  85.  
  86. (* Cursor *)
  87.  
  88. PROCEDURE SetCursorShape(Cursor: WORD);
  89. FUNCTION  GetCursorShape: WORD;
  90. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  91.  
  92. (* Screen *)
  93. PROCEDURE Get4DOSVer;
  94. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  95.  
  96. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  97. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD);
  98. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed: BOOLEAN);
  99. PROCEDURE ShowHelp;
  100.  
  101. (* Keyboard *)
  102.  
  103. FUNCTION GetKey: WORD;
  104.  
  105.  
  106. IMPLEMENTATION USES HandleINIFile, Dos;
  107.  
  108. VAR s: STRING;
  109.  
  110. (*------------------------------------------------------------- Min/Max *)
  111. FUNCTION Min(a,b : INTEGER): INTEGER;
  112.  
  113. BEGIN
  114.  IF a < b THEN Min := a
  115.           ELSE Min := b;
  116. END;
  117.  
  118. FUNCTION Max(a,b : INTEGER): INTEGER;
  119.  
  120. BEGIN
  121.  IF a > b THEN Max := a
  122.           ELSE Max := b;
  123. END;
  124.  
  125.  
  126. (* -------------------------------------------------------- Cursor *)
  127.  
  128. PROCEDURE SetCursorShape(Cursor: WORD); ASSEMBLER;
  129.  
  130. ASM
  131.  mov ah,01h
  132.  mov cx,Cursor
  133.  Int 10h
  134. END;
  135.  
  136. FUNCTION  GetCursorShape: WORD; ASSEMBLER;
  137.  
  138. ASM
  139.  mov ah,03h
  140.  mov bh,0
  141.  Int 10h
  142.  mov ax,cx
  143. END;
  144.  
  145. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  146.  
  147. VAR Cursor : WORD;
  148.  
  149. BEGIN
  150.  IF Overwrite THEN Cursor := $0007
  151.               ELSE Cursor := $0607;
  152.  SetCursorShape(Cursor);
  153. END; (* ResetCursor *)
  154.  
  155.  
  156. (* -------------------------------------------------------- Screen *)
  157. PROCEDURE Get4DOSVer;
  158.  
  159. VAR Regs    : Registers;
  160.     _4dvmaj : STRING[1];
  161.     _4dvmin : STRING[2];
  162.  
  163. BEGIN
  164.  Regs.ax := $D44D;
  165.  Regs.bx := $0;
  166.  Intr($2F,Regs);
  167.  IF Regs.ax = $44DD THEN    (* 4DOS is active *)
  168.   BEGIN
  169.    Str(Regs.bl:1,_4dvmaj);
  170.    Str(Regs.bh:2,_4dvmin);
  171.    IF _4dvmin[1] = ' ' THEN _4dvmin[1] := '0';
  172.    _4DOSVer := ' 4DOS ' + _4dvmaj + '.' + _4dvmin + ' ';
  173.   END
  174.  ELSE
  175.   _4DOSVer := '───────────';
  176. END;  (* Get4DOSVer *)
  177.  
  178. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  179.  
  180. VAR ch : WORD;
  181.  
  182. BEGIN
  183.  TextColor(WarnFg); TextBackGround(WarnBg);
  184.  GotoXY(1,MaxLines); Write(msg); ClrEol;
  185.  REPEAT UNTIL KeyPressed;
  186.  ch := GetKey;  (* Throw away keystroke. *)
  187.  DrawStatusLine(TRUE,FullClipBoard,Changed);
  188. END; (* ReportError *)
  189.  
  190. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed: BOOLEAN);
  191.  
  192. BEGIN
  193.  TextBackGround(NormBg);
  194.  IF Redraw THEN
  195.   BEGIN
  196.    TextColor(NormFg); ClrEol;
  197.    GotoXY(1,MaxLines);
  198.    Write('───────────────────────────────────────────────────────────────────────────────');
  199.   END;
  200.  
  201.  GotoXY(76,MaxLines);
  202.  IF FullClipBoard THEN BEGIN TextColor(HighFg); Write('Cut'); END
  203.                   ELSE BEGIN TextColor(NormFg); Write('───'); END;
  204.  
  205.  GotoXY(70,MaxLines);
  206.  IF Changed THEN BEGIN TextColor(HighFg); Write('Edit'); END
  207.             ELSE BEGIN TextColor(NormFg); Write('────'); END;
  208.  TextColor(NormFg); GotoXY(3,MaxLines); Write(_4DOSVer);
  209. END; (* DrawStatusLine *)
  210.  
  211. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD);
  212.  
  213. BEGIN
  214.  TextColor(NormFg); TextBackGround(NormBg);
  215.  ClrScr;
  216.  TextColor(StatusFg); TextBackGround(StatusBg);
  217.  GotoXY(1,1);
  218.  Write(' ESC exits │ ',Chr(24),' or ',Chr(25),' Selects │               │',
  219.        ' F2 or F10 Saves │ Line ',Index:3,' of ',NrOfFiles:3,' ');
  220.  DrawStatusLine(TRUE,FALSE,FALSE);
  221. END; (* DrawMainScreen *)
  222.  
  223. PROCEDURE ShowHelp;
  224.  
  225. VAR cursor, ch : WORD;
  226.  
  227. BEGIN
  228.  TextBackGround(NormBg);
  229.  ClrScr;
  230.  TextColor(DirFg);
  231.  GotoXY(35,01); Write('4DESC Help');
  232.  TextColor(NormFg);
  233.  GotoXY(9,02); Write('USAGE:  4DESC [/help] [/mono] [d:][\path\][descript.ion]');
  234.  
  235.  GotoXY(9,04); Write('UpArr, DnArr, PgUp, PgDn:  Move highlight bar');
  236.  GotoXY(9,05); Write('LtArr, RtArr, Home, End:   Move cursor');
  237.  GotoXY(9,06); Write('Ctrl-PgUp, Ctrl-PgDn:      Move to first or last line');
  238.  GotoXY(9,08); Write('Backspace:        Delete the character before the cursor');
  239.  GotoXY(9,09); Write('DEL:              Delete the character under  the cursor');
  240.  GotoXY(9,10); Write('Ctrl-End:         Delete from cursor to end of line');
  241.  GotoXY(9,11); Write('INS:              Toggle from insert mode (default) to overwrite mode ');
  242.  GotoXY(9,12); Write('Alt-D:            Delete current description');
  243.  GotoXY(9,13); Write('Alt-C:            Copy current description to buffer');
  244.  GotoXY(9,14); Write('Alt-M, Alt-T:     Move current description to buffer');
  245.  GotoXY(9,15); Write('Alt-P:            Paste buffer to current description');
  246.  GotoXY(9,16); Write('Alt-V, F3:        View higlighted file');
  247.  GotoXY(9,17); Write('Alt-S, Shift-F10: Shell to (4)DOS');
  248.  GotoXY(9,18); Write('Alt-X, ESC:       Exit program');
  249.  GotoXY(9,20); Write('F4 or ENTER on dir :  Change to highlighted directory');
  250.  GotoXY(9,21); Write('F5 or ENTER on ..  :  Change to parent directory');
  251.  GotoXY(9,22); Write('F6 or Alt-L        :  Change drive');
  252.  GotoXY(9,24); Write('4DESC ',ver,' - (c) 1992 Copyright by David Frey & Tom Bowden');
  253.  GotoXY(26,25); Write('Press any key to return.');
  254.  
  255.  Cursor := $2000; SetCursorShape(Cursor);   (* Hide cursor. *)
  256.  REPEAT UNTIL KeyPressed;
  257.  ch := GetKey;             (* Throw away keystroke. *)
  258. END; (* ShowHelp *)
  259.  
  260. (* -------------------------------------------------------- Keyboard *)
  261.  
  262. FUNCTION GetKey: WORD;
  263.  
  264. VAR chlo, chhi : CHAR;
  265.  
  266. BEGIN
  267.  REPEAT UNTIL KeyPressed;
  268.  chlo := ReadKey;
  269.  IF chlo = #0 THEN chhi := ReadKey
  270.               ELSE chhi := #0;
  271.  GetKey := WORD(chhi) SHL 8 + BYTE(chlo);
  272. END;
  273.  
  274.  
  275. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  276.  
  277. BEGIN
  278.  IF Monochrome THEN
  279.   IF INIFileExists THEN
  280.    BEGIN
  281.     DirFg    := ReadSettingsColor('monodisplay','dirfg'   ,mo_DirFg);
  282.     StatusFg := ReadSettingsColor('monodisplay','statusfg',mo_StatusFg);
  283.     StatusBg := ReadSettingsColor('monodisplay','statusbg',mo_StatusBg);
  284.     SelectFg := ReadSettingsColor('monodisplay','selectfg',mo_SelectFg);
  285.     SelectBg := ReadSettingsColor('monodisplay','selectbg',mo_SelectBg);
  286.     HighFg   := ReadSettingsColor('monodisplay','highfg'  ,mo_HighFg);
  287.     NormFg   := ReadSettingsColor('monodisplay','normfg'  ,mo_NormFg);
  288.     NormBg   := ReadSettingsColor('monodisplay','normbg'  ,mo_NormBg);
  289.     WarnFg   := ReadSettingsColor('monodisplay','warnfg'  ,mo_WarnFg);
  290.     WarnBg   := ReadSettingsColor('monodisplay','warnbg'  ,mo_WarnBg);
  291.    END
  292.   ELSE
  293.    BEGIN
  294.     DirFg    := mo_DirFg;
  295.     StatusFg := mo_StatusFg; StatusBg := mo_StatusBg;
  296.     SelectFg := mo_SelectFg; SelectBg := mo_SelectBg;
  297.     HighFg   := mo_HighFg;
  298.     NormFg   := mo_NormFg;   NormBg   := mo_NormBg;
  299.     WarnFg   := mo_WarnFg;   WarnBg   := mo_WarnBg;
  300.    END
  301.  ELSE
  302.   IF INIFileExists THEN
  303.    BEGIN
  304.     DirFg    := ReadSettingsColor('colordisplay','dirfg'   ,co_DirFg);
  305.     StatusFg := ReadSettingsColor('colordisplay','statusfg',co_StatusFg);
  306.     StatusBg := ReadSettingsColor('colordisplay','statusbg',co_StatusBg);
  307.     SelectFg := ReadSettingsColor('colordisplay','selectfg',co_SelectFg);
  308.     SelectBg := ReadSettingsColor('colordisplay','selectbg',co_SelectBg);
  309.     HighFg   := ReadSettingsColor('colordisplay','highfg'  ,co_HighFg);
  310.     NormFg   := ReadSettingsColor('colordisplay','normfg'  ,co_NormFg);
  311.     NormBg   := ReadSettingsColor('colordisplay','normbg'  ,co_NormBg);
  312.     WarnFg   := ReadSettingsColor('colordisplay','warnfg'  ,co_WarnFg);
  313.     WarnBg   := ReadSettingsColor('colordisplay','warnbg'  ,co_WarnBg);
  314.    END
  315.   ELSE
  316.    BEGIN
  317.     DirFg    := co_DirFg;
  318.     StatusFg := co_StatusFg; StatusBg := co_StatusBg;
  319.     SelectFg := co_SelectFg; SelectBg := co_SelectBg;
  320.     HighFg   := co_HighFg;
  321.     NormFg   := co_NormFg;   NormBg   := co_NormBg;
  322.     WarnFg   := co_WarnFg;   WarnBg   := co_WarnBg;
  323.    END;
  324. END;
  325.  
  326. BEGIN
  327.  Get4DOSVer;
  328.  OrigCursor := GetCursorShape;
  329.  MaxLines   := Hi(WindMax)+1;
  330.  ScreenSize := MaxLines-3;
  331.  monochrome := (LastMode = Mono);
  332.  
  333.  IF INIFileExists THEN
  334.   BEGIN
  335.    s := ReadSettingsString('generaldisplay','leftjust','n');
  336.    NoJust := (s[1] = 'y');
  337.    s := ReadSettingsString('generaldisplay','fullsize','n');
  338.    FullSize := (s[1] = 'y');
  339.   END
  340.  ELSE
  341.   BEGIN
  342.    NoJust := FALSE;
  343.    FullSize := FALSE;
  344.   END;
  345. END.
  346.